package zhaomh.catgirl;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class zConfig {
    public static YamlConfiguration data;
    public static FileConfiguration dConfig;
    private static File data_file;
    public static YamlConfiguration language;
    private static zTools t = new zTools("&d[猫娘ねこむすめ]",null);
    private zConfig () {
        reloadConfig();
    }
    public static void reloadConfig () {
        data_file = new File(t.getPlugin().getDataFolder(),"data.yml");
        data = YamlConfiguration.loadConfiguration(data_file);

        //data.addDefault("catgirls", Map.of("name","player1","owner","null","goodwill",0));
        //data.options().copyDefaults(true);

        dConfig = YamlConfiguration.loadConfiguration(new File(t.getPlugin().getDataFolder(),"config.yml"));;

        File language_file = new File(t.getPlugin().getDataFolder(),"language.yml");
        File file = new File("plugins/catgirl/language");
        if (!language_file.exists()) {
            t.getPlugin().saveResource("language.yml", false);
        }

        language = YamlConfiguration.loadConfiguration(language_file);
    }
    public static void saveConfig() {
        try {
            data.save (data_file);
            dConfig.save (new File(CatGirl.getPlugin(CatGirl.class).getDataFolder(),"config.yml"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        reloadConfig();
    }
    public static String getLanguage(String path) {
        String string = language.getString(path);
        string = t.colorReplace(string);
        return string;
    }
    public static List<String> getLanguageList(String path) {
        List<String> stringList = language.getStringList(path);
        stringList.replaceAll(str -> t.colorReplace(str));
        return stringList;
    }
}
